//
//  MoreServiceVC.m
//  hnGovernment
//
//  Created by 安仔 on 2017/3/18.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "MoreServiceVC.h"
#import "HPContentCell.h"
#import "SserviceByCategoryObj.h"
#import "DTWebViewController.h"
@interface MoreServiceVC ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *myCollectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end

@implementation MoreServiceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = NSLocalString(@"更多服务");
    
    [self createCollectionView];
    
}
//初始化网格视图
- (void)createCollectionView {
    self.layout = [[UICollectionViewFlowLayout alloc] init]; // 自定义的布局对象
    self.layout.minimumInteritemSpacing = 0;
    self.layout.minimumLineSpacing = 0;
    self.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    self.myCollectionView.dataSource = self;
    self.myCollectionView.delegate = self;
    [self.view addSubview:self.myCollectionView];
    //注册网格cell
    [self.myCollectionView registerClass:[HPContentCell class] forCellWithReuseIdentifier:@"moreServiceCell"];
}

#pragma mark ---- UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.collectArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HPContentCell *cell = [self.myCollectionView dequeueReusableCellWithReuseIdentifier:@"moreServiceCell" forIndexPath:indexPath];
    SserviceByCategoryObj *obj = self.collectArray[indexPath.item];
    //重写title的位置
    if ([obj.intro isEqualToString:@""]) {
        [cell.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(cell.signImg.mas_centerY);
            make.left.mas_equalTo(cell.signImg.mas_right).offset(26*m6Scale);
        }];
    } else { }
    cell.titleLab.text = obj.serviceName;
    cell.detailsLab.text = obj.intro;
    [cell.signImg sd_setImageWithURL:[NSURL URLWithString:obj.serviceImg]];
    return cell;
}

#pragma mark ---- UICollectionViewDelegateFlowLayout
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    return CGSizeMake(KScreenWidth/2, 150*m6Scale);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

#pragma mark ---- UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    SserviceByCategoryObj *obj = self.collectArray[indexPath.item];
    DTWebViewController *webViewController = [[DTWebViewController alloc]init];
    webViewController.webViewUrlString = obj.url;
    webViewController.title = obj.serviceName;
    [self.navigationController pushViewController:webViewController animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
